
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <link href="${base}/resource/admin/css/common.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="${base}/resource/admin/js/jquery.js"></script>
    <script type="text/javascript" src="${base}/resource/admin/js/common.js"></script>
    <script type="text/javascript" src="${base}/resource/admin/js/list.js"></script>
    <style type="text/css">
        .map{
            height: 100%;
            width: 100%;
            min-height: 700px;
        }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=A6ebf3292d0ac730ec570674279d1d98"></script>
    <title>单击获取点击的经纬度</title>
</head>
<body>
<!-- 地址导航-->
<div class="path">
    获取坐标
</div>
<!-- 主体-->
<form id="listForm" action="#" method="get" onsubmit="return search();">
    <div class="searchBar">
        <table class="searchContent">
            <tr>
                <td>
                    坐标Lng：
                    <input type="text" class="text" name="lng"  readonly="readonly" value="${lng}"/>
                </td>
                <td>
                    坐标Lat：
                    <input type="text"  class="text" name="lat" readonly="readonly" value="${lat}"/>
                </td>
            </tr>
            <tr>
                <td>
                    查询
                    <input type="text"  class="text"  name="tag" value="${tag}"/>
                </td>
                <td>
                    <button type="submit">检索</button>
                </td>
            </tr>
        </table>
    </div>
    <div class="bar">
        <a href="javascript:dataBack();" class="iconButton">
            <span class="addIcon">&nbsp;</span>参数带回
        </a>
        <div class="buttonWrap">
            <a href="javascript:;" id="refreshButton" class="iconButton">
                <span class="refreshIcon">&nbsp;</span>刷新
            </a>
        </div>
    </div>
    <div class="map" id="bdMap">

    </div>
</form>
<script type="text/javascript">


   /* var lng,lat;
    var index = parent.layer.getFrameIndex(window.name);
    map.addEventListener("click",function(e){
        lng=e.point.lng;
        lat=e.point.lat;
        parent.$("input[name='lng']").val(lng);
        parent.$("input[name='lat']").val(lat);
        parent.layer.close(index);
    });*/



   var map = null;
   var point = null;
   var myGeo = null;
   var lng,lat;

   /** 加载地图*/
   function initMap() {
       map = new BMap.Map("bdMap");
        point = new BMap.Point(116.331398,39.897445);
       map.centerAndZoom(point,16);

       myGeo = new BMap.Geocoder();   //解析器
       //地图点击事件
       map.addEventListener("click", function (e) {
           lng = e.point.lng;
           lat = e.point.lat;
           $("input[name='lng']").val(lng);
           $("input[name='lat']").val(lat);
       });
       //初始化form
       var $tagInitVal = $("input[name='tag']");
       if($tagInitVal.val()!='undefined'){
           markerByTag($tagInitVal.val());
       }

   }

   /* 通过tag标识地图 */
   function markerByTag(tag) {
       myGeo.getPoint(tag, function (point) {
           if (point) {
               map.centerAndZoom(point, 16);
               map.addOverlay(new BMap.Marker(point));
           }
       }, "武汉市");
   }

    /** form搜索*/
   function search() {
       var $tagVal = $("input[name='tag']");
       markerByTag($tagVal.val());
       return false;
   }


   function dataBack(){
       var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
       parent.$("input[name='lng']").val(lng);
       parent.$("input[name='lat']").val(lat);
       parent.layer.close(index);
       return false;
   }

   initMap();

</script>


</body>
</html>
